package com.demo.service;

import com.demo.dao.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    //1.属性注入
    @Autowired  //DI(依赖注入)
    private UserRepository userRepository;

    public int add(){
        System.out.println("Do UserRepository add method!!!");

//        //传统写法
//        UserRepository userRepository=new UserRepository();
//        return userRepository.add();

//        //spring 1.0写法
//        ApplicationContext context=new ClassPathXmlApplicationContext("spring-config.xml");
//        UserRepository userRepository=context.getBean("userRepository",UserRepository.class);
//        userRepository.add();

        //spring 2.0写法
        return userRepository.add();
    }
}
